package com.asktgapp.user.fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.asktgapp.JGTool.JGColor;
import com.asktgapp.JGTool.Utils;
import com.asktgapp.R;
import com.asktgapp.application.ApiUtil;
import com.asktgapp.application.Apiservice;
import com.asktgapp.application.MyApplication;
import com.asktgapp.architecture.retrofit.ApiException;
import com.asktgapp.architecture.retrofit.ApiResponseBody;
import com.asktgapp.architecture.rxjava.ExceptionHandle;
import com.asktgapp.base.BaseFragment;
import com.asktgapp.base.SearchBaseActivity;
import com.asktgapp.eventbus.HomeEvent;
import com.asktgapp.eventbus.WebEvent;
import com.asktgapp.model.FreeAskSearchVO;
import com.asktgapp.model.NewHomeOneBean;
import com.asktgapp.model.NewHomeTwoBean;
import com.asktgapp.modulebase.common.adapter.BaseAdapter;
import com.asktgapp.modulebase.common.adapter.BaseViewHolder;
import com.asktgapp.modulebase.common.util.PreferencesUtil;
import com.asktgapp.modulebase.common.util.Util;
import com.asktgapp.user.activity.EngineerListActivity;
import com.asktgapp.user.activity.FreeAskActivity;
import com.asktgapp.user.activity.FreeAskAnswerDetailActivity;
import com.asktgapp.user.activity.HomeServiceActivity;
import com.asktgapp.user.activity.IndurstryInformationActivity;
import com.asktgapp.user.activity.IndustryInfoDetailActivity;
import com.asktgapp.user.activity.MessageCenterActivity;
import com.asktgapp.user.activity.NewWebActivity;
import com.asktgapp.user.activity.RentMachineNewActivity;
import com.asktgapp.user.activity.UsedMachineDetailActivity;
import com.asktgapp.user.activity.UsedSecondhandTypeActivity;
import com.asktgapp.utils.ImageDisplayUtil;
import com.asktgapp.widget.HomeBannerViewpPager;
import com.asktgapp.widget.JDAdverView;
import com.asktgapp.widget.JDViewAdapter;
import com.sobot.chat.SobotApi;
import com.yanzhenjie.recyclerview.swipe.widget.DefaultItemDecoration;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;


public class NewNewHomeFragment extends BaseFragment {

    private BaseAdapter Question, Goods, SecondHand, CommonSense;
    //搜索框
    @InjectView(R.id.et_search)
    EditText mSearch;
    //消息图标
    @InjectView(R.id.iv_message)
    ImageView mMessage;
    @InjectView(R.id.recycleQuestion)
    RecyclerView recycleQuestion;
    @InjectView(R.id.recycleGoods)
    RecyclerView recycleGoods;
    @InjectView(R.id.recycleSecondHand)
    RecyclerView recycleSecondHand;
    @InjectView(R.id.recycleCommonSense)
    RecyclerView recycleCommonSense;
    @InjectView(R.id.homeMoreQuestion)
    RelativeLayout homeMoreQuestion;
    @InjectView(R.id.tvHomeMoreGoods)
    TextView tvHomeMoreGoods;
    @InjectView(R.id.tvHomeMoreSecondHand)
    TextView tvHomeMoreSecondHand;
    @InjectView(R.id.tvHomeMoreCommonSense)
    TextView tvHomeMoreCommonSense;
    @InjectView(R.id.banne)
    HomeBannerViewpPager banne;
    @InjectView(R.id.tv_item1)
    TextView tv_item1;
    @InjectView(R.id.tv_item2)
    TextView tv_item2;
    @InjectView(R.id.tv_item3)
    TextView tv_item3;
    @InjectView(R.id.tv_item5)
    TextView tv_item5;
    @InjectView(R.id.rl_free_ask)
    RelativeLayout rl_free_ask;
    @InjectView(R.id.rlShop)
    RelativeLayout rlShop;

    @InjectView(R.id.ivHead1)
    ImageView ivHead1;
    @InjectView(R.id.ivHead2)
    ImageView ivHead2;
    @InjectView(R.id.srlHome)
    SwipeRefreshLayout srlHome;
    @InjectView(R.id.jdView)
    JDAdverView jdView;
    @InjectView(R.id.tv_des1)
    TextView tv_des1;
    @InjectView(R.id.tv_des2)
    TextView tv_des2;

    @InjectView(R.id.tvMsgNum)
    TextView tvMsgNum;
    private int mBanHeight;
    private boolean needResume = false;
    private int mPage = 1;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        ViewGroup viewGroup = (ViewGroup) inflater.inflate(R.layout.fragment_home_new_new, container, false);
        ButterKnife.inject(this, viewGroup);
        EventBus.getDefault().register(this);
        needResume = false;
        return super.onCreateView(inflater, viewGroup, savedInstanceState);
    }

    @Override
    protected void initView(View rootView) {
        WindowManager windowManager = (WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE);
        Display display = windowManager.getDefaultDisplay();
        mBanHeight = display.getWidth() * 1 / 2;
        banne.setVisibility(View.VISIBLE);
        banne.setH(mBanHeight);
        tv_item1.setOnClickListener(this);
        tv_item2.setOnClickListener(this);
        tv_item3.setOnClickListener(this);
        tv_item5.setOnClickListener(this);
        rlShop.setOnClickListener(this);
        rl_free_ask.setOnClickListener(this);
        homeMoreQuestion.setOnClickListener(this);
        tvHomeMoreCommonSense.setOnClickListener(this);
        tvHomeMoreSecondHand.setOnClickListener(this);
        tvHomeMoreGoods.setOnClickListener(this);
        mSearch.setOnClickListener(this);
//        mBanner.loadBannerData(indexVO.getBannerList());
//        srlHome.setNestedScrollingEnabled(false);
        srlHome.setColorSchemeColors(0xFF3399fe);
        srlHome.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                if (srlHome.isRefreshing())
                    srlHome.setRefreshing(false);
                newHomeOne();
            }
        });
        Question = new BaseAdapter(getActivity()) {
            @Override
            public BaseViewHolder getViewHolder(ViewGroup parent, int viewType) {
                BaseViewHolder holder = new BaseViewHolder(LayoutInflater.from(getActivity()).inflate(R.layout.item_home_ask_hot, parent, false),
                        new BaseViewHolder.Callbacks2() {
                            @Override
                            public void bind(BaseViewHolder holder, Object data) {
                                if (data instanceof NewHomeOneBean.QuestionListBean) {
                                    NewHomeOneBean.QuestionListBean bean = (NewHomeOneBean.QuestionListBean) data;
                                    ImageView ivQuestionHead = holder.getView(R.id.ivQuestionHead);
                                    ImageView ivAnswerHead = holder.getView(R.id.ivAnswerHead);
                                    ImageDisplayUtil.loadCircleHeadImage(getActivity(), ivQuestionHead, bean.getqUserPic());
                                    holder.setText(R.id.tvZan, String.valueOf(bean.getLikeNumber()));
                                    holder.setText(R.id.tvQuestionName, bean.getqUersName());
                                    holder.setText(R.id.tvQuestionContent, bean.getqContent());
                                    holder.setText(R.id.tvQuestionName, bean.getqUersName());

                                    ImageDisplayUtil.loadCircleHeadImage(getActivity(), ivAnswerHead, bean.getaUserPic());
                                    holder.setText(R.id.tvAnswerName, bean.getaRealName());
                                    holder.setText(R.id.tvCommentType, "工程师");
                                    holder.setText(R.id.state, "已解答");
//                                    if (TextUtils.isEmpty(bean.getaLabel())) {
//
//                                    } else
//                                        holder.setText(R.id.tvCommentType, bean.getaLabel());
                                    holder.setText(R.id.Number, "评论" + bean.getAnswerNum());

//                                    ImageView ivZan = holder.getView(R.id.ivZan);
//
//
//                                    if (TextUtils.isEmpty(bean.get()))
//                                        ivZan.setImageResource(R.mipmap.zan_2);
//                                    else {
//                                        ivZan.setImageResource(R.mipmap.zan_1);
//                                    }
//                                    holder.getView(R.id.zan).setOnClickListener(new View.OnClickListener() {
//                                        @Override
//                                        public void onClick(View v) {
//                                            //点赞接口
//                                            if (TextUtils.isEmpty(bean.getLikeId())) {
//                                                dealZan(bean.getId(), "1", bean);
//                                            } else {
//                                                dealZan(bean.getId(), "0", bean);
//                                            }
//                                            index = Question.getItemIndex(bean);
//                                        }
//                                    });
                                }
                            }

                            @Override
                            public void onItemClick(BaseViewHolder holder, View view, int position) {
                                if (!checkIsLogin("登录后可查看更多内容"))
                                    return;
                                NewHomeOneBean.QuestionListBean b = (NewHomeOneBean.QuestionListBean) Question.getData(position);

                                FreeAskAnswerDetailActivity.startFreeAskAnswerDetailActivty(String.valueOf(b.getqId()),getContext());
                            }
                        });
                return holder;
            }

        };
        Goods = new BaseAdapter(getActivity()) {
            @Override
            public BaseViewHolder getViewHolder(ViewGroup parent, int viewType) {
                BaseViewHolder holder = new BaseViewHolder(LayoutInflater.from(getActivity()).inflate(R.layout.item_home_goods, parent, false),
                        new BaseViewHolder.Callbacks2() {
                            @Override
                            public void bind(BaseViewHolder holder, Object data) {
                                if (data instanceof NewHomeTwoBean.ShopListBean) {
                                    NewHomeTwoBean.ShopListBean bean = (NewHomeTwoBean.ShopListBean) data;
                                    holder.setText(R.id.tvGoodsName, bean.getBargainInfor());
                                    holder.setText(R.id.tvContent, bean.getShopName());
                                    switch (holder.getAdapterPosition()) {
                                        case 0:
                                            holder.setImageResource(R.id.ivGoodsHeadSm, R.mipmap.shop_hot);
                                            break;
                                        case 1:
                                            holder.setImageResource(R.id.ivGoodsHeadSm, R.mipmap.shop_hot);
                                            break;
                                        case 2:
                                            holder.setImageResource(R.id.ivGoodsHeadSm, R.mipmap.shop_re);
                                            break;
                                        case 3:
                                            holder.setImageResource(R.id.ivGoodsHeadSm, R.mipmap.shop_re);
                                            break;
                                    }
                                    ImageView bigIV = holder.getView(R.id.bigIV);
                                    ImageDisplayUtil.LoadNetImageWithUrl(bigIV, getActivity(), bean.getShowPic());
                                }
                            }

                            @Override
                            public void onItemClick(BaseViewHolder holder, View view, int position) {

                                NewHomeTwoBean.ShopListBean bean = (NewHomeTwoBean.ShopListBean) Goods.getData(position);
                                NewWebActivity.start(getActivity(), bean.getShopDetailUrl(), "商品详情", 0);//fengyi // bean.getShopDetailUrl()

//                                if (checkIsLogin("登录后可查看更多内容")) {
//                                    NewHomeTwoBean.ShopListBean bean = (NewHomeTwoBean.ShopListBean) Goods.getData(position);
//                                    String url;
//                                    if (bean.getShopDetailUrl().contains("?")) {
//                                        url = bean.getShopDetailUrl()
//                                                + "&userId=" + PreferencesUtil.getString(getActivity(), PreferencesUtil.USER_ID);
//                                    } else {
//                                        url = bean.getShopDetailUrl()
//                                                + "?userId=" + PreferencesUtil.getString(getActivity(), PreferencesUtil.USER_ID) + "&name=jiangong";
//                                    }
//                                    NewWebActivity.start(getActivity(), url, "商品详情");
//                                }
                            }
                        });
                return holder;
            }

        };
        SecondHand = new BaseAdapter(getActivity()) {
            @Override
            public BaseViewHolder getViewHolder(ViewGroup parent, int viewType) {
                BaseViewHolder holder = new BaseViewHolder(LayoutInflater.from(getActivity()).inflate(R.layout.item_used_machine, parent, false),
                        new BaseViewHolder.Callbacks() {
                            @Override
                            public void bind(BaseViewHolder holder, Object data) {
                                if (data instanceof NewHomeTwoBean.SecondMachineListBean) {
                                    NewHomeTwoBean.SecondMachineListBean bean = (NewHomeTwoBean.SecondMachineListBean) data;
                                    if (SecondHand.getItemIndex(bean) == 0)
                                        holder.getView(R.id.tvLine).setVisibility(View.VISIBLE);
                                    else
                                        holder.getView(R.id.tvLine).setVisibility(View.GONE);
                                    ImageView saleState = holder.getView(R.id.iv_saled);
                                    ImageView img = holder.getView(R.id.iv_machine);
                                    if (bean.getBannerList().size() > 0) {
                                        ImageDisplayUtil.LoadNetImage(img, getActivity(), bean.getBannerList().get(0));
                                    }
                                    holder.setText(R.id.tv_used_machine_name, bean.getTitle());
                                    holder.setText(R.id.detail, Utils.getDateYear(bean.getProductionDate()) +
                                            " | " + Utils.D2I(bean.getWorkingHours()) + "小时 | " + bean.getProvinceName().replaceAll("省", "") + " " + bean.getCityName().replaceAll("市", ""));
                                    DecimalFormat df = new DecimalFormat("0.00");
                                    holder.setText(R.id.tv_price, df.format(bean.getPrice()));
//                                    holder.setText(R.id.tvUnit, bean.getPrice_unit());
                                    Date date = Util.StrToDate(bean.getAddTime(), "yyyy.MM.dd HH:mm:ss");
                                    String timeStr = Utils.getAskTime(date);
                                    holder.setText(R.id.addTime, timeStr);
                                    holder.setText(R.id.tvUnit, "万");
//                                    if (bean.get() == 0) {
//                                        saleState.setVisibility(View.GONE);
//                                    } else {
//                                        saleState.setVisibility(View.VISIBLE);
//                                    }

                                }


                            }

                            @Override
                            public void onItemClick(View view, int position) {
                                if (!checkIsLogin("登录后可查看更多内容"))
                                    return;
                                NewHomeTwoBean.SecondMachineListBean bean = (NewHomeTwoBean.SecondMachineListBean) SecondHand.getData().get(position);
                                Intent intent = new Intent(getActivity(), UsedMachineDetailActivity.class);
                                intent.putExtra("id", String.valueOf(bean.getId()));
                                intent.putExtra("unit", bean.getUnit());
                                startActivity(intent);
                            }
                        });
                return holder;
            }
        };

        CommonSense = new BaseAdapter(getActivity()) {
            @Override
            public BaseViewHolder getViewHolder(ViewGroup parent, int viewType) {
                BaseViewHolder holder = new BaseViewHolder(LayoutInflater.from(getActivity()).inflate(R.layout.item_home_common_sense, parent, false),
                        new BaseViewHolder.Callbacks2() {
                            @Override
                            public void bind(BaseViewHolder holder, Object data) {
                                if (data instanceof NewHomeTwoBean.InformationListBean) {
                                    NewHomeTwoBean.InformationListBean bean = (NewHomeTwoBean.InformationListBean) data;
                                    holder.setText(R.id.tvTitle, bean.getTitle());
                                    holder.setText(R.id.tvName, bean.getUserName());
                                    holder.setText(R.id.readNum, "阅读" + bean.getViewNumber());
                                    holder.setText(R.id.likeNumber, "赞" + bean.getLikeNumber());
                                    ImageView ivAnswerHead = holder.getView(R.id.ivAnswerHead);
                                    ImageDisplayUtil.loadCircleHeadImage(getActivity(), ivAnswerHead, bean.getUserPic());
                                }
                            }

                            @Override
                            public void onItemClick(BaseViewHolder holder, View view, int position) {
                                if (!checkIsLogin("登录后可查看更多内容"))
                                    return;
                                NewHomeTwoBean.InformationListBean b = (NewHomeTwoBean.InformationListBean) CommonSense.getData(position);
                                Intent intent = new Intent(getActivity(), IndustryInfoDetailActivity.class);
                                intent.putExtra("id", String.valueOf(b.getId()));
                                getActivity().startActivity(intent);
                            }
                        });
                return holder;
            }

        };
        List<FreeAskSearchVO> list = new ArrayList<>();

        recycleQuestion.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
        recycleQuestion.setAdapter(Question);

        recycleGoods.setLayoutManager(new GridLayoutManager(getContext(), 2));
        recycleGoods.addItemDecoration(new DefaultItemDecoration(JGColor.APP_BACKGROUND));
        recycleGoods.setAdapter(Goods);
        recycleCommonSense.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
        recycleCommonSense.setAdapter(CommonSense);
        recycleSecondHand.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
        recycleSecondHand.setAdapter(SecondHand);

        recycleSecondHand.setNestedScrollingEnabled(false);
        recycleCommonSense.setNestedScrollingEnabled(false);
        recycleGoods.setNestedScrollingEnabled(false);
        recycleQuestion.setNestedScrollingEnabled(false);

        Question.setData(list);
        Goods.setData(list);
        SecondHand.setData(list);
        CommonSense.setData(list);


    }

    @Override
    public void loadData() {
//        visibleLoading();
        newHomeOne();
        needResume = true;

    }


    private void newHomeOne() {
        showProgress(getClass().getSimpleName());
        Apiservice apiservice = ApiUtil.getInstance().create();
        HashMap params = new HashMap();
        if (!TextUtils.isEmpty(PreferencesUtil.getString(getContext(), PreferencesUtil.USER_ID)))
            params.put("userId", PreferencesUtil.getString(getContext(), PreferencesUtil.USER_ID));
        Call<ApiResponseBody<NewHomeOneBean>> call = apiservice.newHomeOne(params);
        call.enqueue(new Callback<ApiResponseBody<NewHomeOneBean>>() {
            @Override
            public void onResponse(Call<ApiResponseBody<NewHomeOneBean>> call, Response<ApiResponseBody<NewHomeOneBean>> response) {

                if (response.isSuccessful()) {
                    NewHomeOneBean bean = response.body().getResult();
                    if (bean != null) {
                        banne.loadBannerData(bean.getBannerList());
                        Question.setData(bean.getQuestionList());
                        tv_des2.setText(bean.getShopDictionary());
                        tv_des1.setText(bean.getProblemDictionary());
                        if (bean.getProjectUserPic().size() > 1) {
                            ivHead1.setVisibility(View.VISIBLE);
                            ivHead2.setVisibility(View.VISIBLE);
                            ImageDisplayUtil.loadCircleHeadImage(getActivity(), ivHead1, bean.getProjectUserPic().get(0).getUserPic());
                            ImageDisplayUtil.loadCircleHeadImage(getActivity(), ivHead2, bean.getProjectUserPic().get(1).getUserPic());
                        } else if (bean.getProjectUserPic().size() > 0) {
                            ivHead1.setVisibility(View.VISIBLE);
                            ivHead2.setVisibility(View.GONE);
                            ImageDisplayUtil.loadCircleHeadImage(getActivity(), ivHead1, bean.getProjectUserPic().get(0).getUserPic());
                        } else {
                            ivHead1.setVisibility(View.GONE);
                            ivHead2.setVisibility(View.GONE);
                        }

                        if (bean.getNewsPaper().size() > 0) {
                            JDViewAdapter jdAdapter = new JDViewAdapter(bean.getNewsPaper(), getActivity());
                            jdView.setAdapter(jdAdapter);
                            jdView.start();
                        }


                    }

                }

                homeBroadcast();
            }

            @Override
            public void onFailure(Call<ApiResponseBody<NewHomeOneBean>> call, Throwable t) {
                homeBroadcast();
            }
        });
    }

    private int index = -1;

    //点赞接口
    private void dealZan(String id, final String temp, final FreeAskSearchVO bean) {
        if (Util.isEmpty(PreferencesUtil.getString(getActivity(), PreferencesUtil.USER_ID))) {
            showTost("未登录，不能点赞！请先登录", 1);
            return;
        }
        Apiservice apiservice = ApiUtil.getInstance().create();
        HashMap params = new HashMap();

        params.put("temp", temp);
        params.put("type", 2);
        params.put("id", id);
        params.put("userid", PreferencesUtil.getString(getActivity(), PreferencesUtil.USER_ID));
        showProgress(getClass().getSimpleName());
        Call<ApiResponseBody> call = apiservice.doLike(params);
        call.enqueue(new Callback<ApiResponseBody>() {
            @Override
            public void onResponse(Call<ApiResponseBody> call, Response<ApiResponseBody> response) {
                dismissProgress();
//                if (response.isSuccessful()) {
//                    int num = Integer.valueOf(bean.getProblemLikeNum());
//                    if (temp.equals("1")) {
//                        num++;
//                        bean.setLikeId("13");
//                    } else {
//                        num--;
//                        bean.setLikeId(null);
//                    }
//                    bean.setProblemLikeNum(String.valueOf(num));
//                    mBaseAdapter.update(bean, index);
//                } else {
//                    showTost(response.raw().message(), 0);
//                }
            }

            @Override
            public void onFailure(Call<ApiResponseBody> call, Throwable t) {
                dismissProgress();
                ApiException exception = ExceptionHandle.handleException(t);
                if (exception.isTokenInvalid()) {
                    showUnLoginSnackbar();
                } else if (exception.isNetConnected()) {
                    showSetNetworkSnackbar();
                } else {
                    showTost(exception.getMessage(), 1);
                }
            }
        });

    }


    @Subscribe(threadMode = ThreadMode.MAIN)
    public void hasHomeEvent(HomeEvent event) {

        if (checkIsLogin("登录后可查看更多内容")) {
            if (event.getType() == 3) {
                startActivity(new Intent(getActivity(), EngineerListActivity.class));
            } else if (event.getType() == 4) {
                startActivity(new Intent(getActivity(), HomeServiceActivity.class));
            } else if (event.getType() == 900) {
                int num = SobotApi.getUnreadMsg(MyApplication.getInstance(), PreferencesUtil.getString(MyApplication.getInstance(), PreferencesUtil.USER_ID));
                if ( num> 0) {
                    tvMsgNum.setVisibility(View.VISIBLE);
                    tvMsgNum.setText(String.valueOf(num));
                } else {
                    tvMsgNum.setVisibility(View.GONE);
                }
            }
        }
    }

    @Override
    public void onDestroyView() {
        ButterKnife.reset(this);
        super.onDestroyView();

    }

    @Override
    public void onPause() {
        super.onPause();
    }

    @Override
    public void onDestroy() {
        EventBus.getDefault().unregister(this);
        super.onDestroy();

    }

    @Override
    public void onResume() {
        super.onResume();
        int num = SobotApi.getUnreadMsg(MyApplication.getInstance(), PreferencesUtil.getString(MyApplication.getInstance(), PreferencesUtil.USER_ID));
        if ( num> 0) {
            tvMsgNum.setVisibility(View.VISIBLE);
            tvMsgNum.setText(String.valueOf(num));
        } else {
            tvMsgNum.setVisibility(View.GONE);
        }
    }

    private String seeMoreUrl;
    private String beginAsk;

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            //消息中心
            case R.id.iv_message:
                startActivity(new Intent(getActivity(), MessageCenterActivity.class));
                break;
            //搜索
            case R.id.et_search:
                startActivity(new Intent(getActivity(), SearchBaseActivity.class));
                break;
            case R.id.tv_item1:
                if (!checkIsLogin("登录后可查看更多内容"))
                    return;
                startActivity(new Intent(getActivity(), UsedSecondhandTypeActivity.class));
                break;
            case R.id.tv_item2:
                if (!checkIsLogin("登录后可查看更多内容"))
                    return;
                startActivity(new Intent(getActivity(), RentMachineNewActivity.class));
                break;
            case R.id.tv_item3:
                if (!checkIsLogin("登录后可查看更多内容"))
                    return;
                startActivity(new Intent(getActivity(), IndurstryInformationActivity.class));
                break;
            case R.id.tv_item5:
                if (checkIsLogin("登录后可查看更多内容"))
                    startActivity(new Intent(getActivity(), HomeServiceActivity.class));
                break;
            case R.id.rlShop:
//                if (checkIsLogin("登录后可查看更多内容")) {
                if (!TextUtils.isEmpty(seeMoreUrl)) {
                    NewWebActivity.start(getActivity(), seeMoreUrl, "找配件");
                }
//                }

                break;
            case R.id.rl_free_ask:
                if (!checkIsLogin("登录后可查看更多内容"))
                    return;
                startActivity(new Intent(getActivity(), EngineerListActivity.class));
                break;
            case R.id.tvHomeMoreGoods:
                if (!TextUtils.isEmpty(seeMoreUrl)) {
                    NewWebActivity.start(getActivity(), seeMoreUrl, "找配件");
                }
                break;
            case R.id.tvHomeMoreCommonSense:
                if (!checkIsLogin("登录后可查看更多内容"))
                    return;
                startActivity(new Intent(getActivity(), IndurstryInformationActivity.class));
                break;
            case R.id.homeMoreQuestion:
                if (!checkIsLogin("登录后可查看更多内容"))
                    return;
                startActivity(new Intent(getActivity(), FreeAskActivity.class));
                break;
            case R.id.tvHomeMoreSecondHand:
                if (!checkIsLogin("登录后可查看更多内容"))
                    return;
                startActivity(new Intent(getActivity(), UsedSecondhandTypeActivity.class));
                break;

        }

    }

    public void homeBroadcast() {
        Apiservice apiservice = ApiUtil.getInstance().create();
        HashMap params = new HashMap();
        Call<ApiResponseBody<NewHomeTwoBean>> call = apiservice.newHomeTwo(params);
        call.enqueue(new Callback<ApiResponseBody<NewHomeTwoBean>>() {
            @Override
            public void onResponse(Call<ApiResponseBody<NewHomeTwoBean>> call, Response<ApiResponseBody<NewHomeTwoBean>> response) {
                if (response.isSuccessful()) {
                    NewHomeTwoBean bean = response.body().getResult();
                    if (bean != null) {
                        SecondHand.setData(bean.getSecondMachineList());
                        CommonSense.setData(bean.getInformationList());
                        Goods.setData(bean.getShopList());
                        seeMoreUrl = bean.getSeeMore();
                        beginAsk = bean.getBeginAsk();
                        WebEvent.postEvent(seeMoreUrl, false);
                    }
                } else {
                    showTost(response.raw().message(), 1);
                }
                dismissProgress();

            }

            @Override
            public void onFailure(Call<ApiResponseBody<NewHomeTwoBean>> call, Throwable t) {
                dismissProgress();
                ApiException apiException = ExceptionHandle.handleException(t);
                if (apiException.isTokenInvalid()) {
                    showUnLoginSnackbar();
                } else if (apiException.isNetConnected()) {
                    showSetNetworkSnackbar();
                } else {
                    showTost(apiException.getMessage(), 0);
                }
            }
        });
    }
}
